package com.lagou.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateFormatUtil {

    private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat();

    public static String date2String(String pattern, Date date){
        simpleDateFormat.applyPattern(pattern);
        return simpleDateFormat.format(date);
    }

    public static Date string2Date(String pattern,String dateString){
        simpleDateFormat.applyPattern(pattern);
        try {
            return simpleDateFormat.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
